package com.itheima.filter; /**
 * @author MaQing
 * @create 2022-05-10 08:32
 */

import javax.servlet.*;
import javax.servlet.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@WebFilter( "/*")
public class encodingFilter implements Filter {
    public void init(FilterConfig config) throws ServletException {
    }

    public void destroy() {
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {
        HttpServletRequest request1 = (HttpServletRequest) request;
        String method = request1.getMethod();
        if ("POST".equalsIgnoreCase(method)){
            request1.setCharacterEncoding("utf-8");
        }
        chain.doFilter(request1, response);
    }
}
